
Partial Class Presentation_CheckClientExists
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim Sql As String
        Dim CountSql As String
        Dim Params(0) As GenParameter

        Page.Title = "Check if Client Exists"

        Sql = "Select ClientName, ExecutiveName, DATE_FORMAT(CADate, '%d-%b-%y') AS 'Date Allotted', Location, If(Active = 1, 'Still in the Company', 'Left the Company') AS 'Executive Status', IF(WorkflowMaster.MeetingDate IS NOT NULL, DATE_FORMAT(MAX(Workflowmaster.MeetingDate),'%d-%b-%y'), 'Never Interacted') AS 'Last Interacted' from ClientMaster INNER JOIN ((CompanyAssignments LEFT OUTER JOIN WorkflowMaster ON CompanyAssignments.ClientID = WorkflowMaster.ClientID) INNER JOIN ExecutiveMaster ON ExecutiveMaster.ExecutiveID = CompanyAssignments.ExecutiveID) ON CompanyAssignments.ClientID = ClientMaster.ClientID where ClientName LIKE CONCAT('%',?ClientPart,'%')" & _
            " GROUP BY ClientName, ExecutiveName, 'Date Allotted', Location, 'Executive Status'" & _
            " ORDER BY ClientName"

        CountSql = "Select Count(*) FROM (Select ClientName, ExecutiveName, DATE_FORMAT(CADate, '%d-%b-%y') AS 'Date Allotted', Location, If(Active = 1, 'Still in the Company', 'Left the Company') AS 'Executive Status', DATE_FORMAT(MAX(Workflowmaster.MeetingDate),'%d-%b-%y') AS 'Last Interacted' from ClientMaster INNER JOIN ((CompanyAssignments LEFT OUTER JOIN WorkflowMaster ON CompanyAssignments.ClientID = WorkflowMaster.ClientID) INNER JOIN ExecutiveMaster ON ExecutiveMaster.ExecutiveID = CompanyAssignments.ExecutiveID) ON CompanyAssignments.ClientID = ClientMaster.ClientID where ClientName LIKE CONCAT('%',?ClientPart,'%')" & _
            " GROUP BY ClientName, ExecutiveName, 'Date Allotted', Location, 'Executive Status'" & _
            " ORDER BY ClientName) AS Temp"


        Params(0) = New GenParameter("?ClientPart", txtClientPart.Text, Data.DbType.String)

        If Page.IsPostBack Then
            Page.Validate()
            If Page.IsValid = False Then
                Return
            End If
        End If

        ClientExists.Sql = Sql
        ClientExists.CountSql = CountSql
        ClientExists.Params = Params
        ClientExists.ShowButton = True

    End Sub
End Class
